package com.chenfan.mcn.enums;

import com.chenfan.common.extension.dict.DictTranslator;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 意向单状态枚举
 * @author wulg
 * @date 2022/10/28
 */
@AllArgsConstructor
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum IntentionOrderStatusEnum implements DictTranslator<Integer, String>  {

    DRAFT(0, "草稿"),
    WAIT_ACCEPT(1, "待接单"),
    REFUSED(2, "已拒单"),
    WAIT_LOCK(3, "待锁档"),
    WAIT_AE_LEADER_CONFIRM(4, "待AE主管确认"),
    EXECUTING(5, "执行中"),
    EXECUTED(8, "执行完成"),
    FINNISHED(6, "已完结"),
    INVALID(7, "已作废"),
    CONRIMED(9, "已确认"),
    REJECTED(10, "已驳回"),
    ;

    @Getter
    private final Integer code;

    @Getter
    private final String statusName;

    public static IntentionOrderStatusEnum toEnum(Integer code) {
        if(Objects.isNull(code)) {
            return null;
        }
        IntentionOrderStatusEnum statusEnum = null;
        for (IntentionOrderStatusEnum item : IntentionOrderStatusEnum.values()) {
            if(item.getCode().equals(code)) {
                statusEnum = item;
                break;
            }
        }
        return statusEnum;
    }

    public static String getStatusName(Integer code) {
        IntentionOrderStatusEnum statusEnum = toEnum(code);
        if(Objects.isNull(statusEnum)) {
            return null;
        }
        return statusEnum.statusName;
    }

    public static boolean isAeLeaderConfirm(int code) {
        return IntentionOrderStatusEnum.WAIT_AE_LEADER_CONFIRM.getCode().intValue() == code;
    }

    public static boolean isInvalid(int code) {
        return IntentionOrderStatusEnum.INVALID.getCode().intValue() == code;
    }


    /** 根据状态码任意匹配
     * @param code
     * @param items
     * @return
     */
    public static boolean anyMatch(Integer code, IntentionOrderStatusEnum... items) {
        boolean match = false;
        if(code != null) {
            for(IntentionOrderStatusEnum item : items) {
                if(item.getCode().equals(code)) {
                    match = true;
                    break;
                }
            }
        }
        return match;
    }

    @Override
    public String translate(Integer code) {
        return Objects.nonNull(code) ? getStatusName(code.intValue()) : null;
    }

}
